﻿using Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Utility;
using System.Utility.Messaging;
using System.Utility.UI;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UI.Classes;

namespace UI
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string pageurl = Constant.LoginUrl;
            try
            {
                AppUser u = AppUser.GetUser(txtName.Text, txtPass.Text);

                if (u == null)
                    PageUtility.RegisterClientScriptBlockByMessageId(this, "GE0001");
                else
                {
                    StateManager<AppUser>.SetSessionState(SessionKey.UserInfo, u);
                    //switch (u.Type)
                    //{
                    //    case AppUserType.Admin:
                            pageurl = "default.aspx";
                    //        break;
                    //}
                    Response.Redirect(pageurl);
                }
            }
            catch (Exception ex)
            {
                MessageUtility.LogAndGetMessageCode(ex);
                PageUtility.RegisterClientScriptBlockByMessageId(this, "GE0001");
            }
        }
    }
}